package com.skivingcloud.webflux.demo.controller;

import com.skivingcloud.webflux.demo.service.DemoService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@RestController
@RequestMapping("/demo")
public class DemoController {

    private DemoService demoService;

    public DemoController(DemoService demoService) {
        this.demoService = demoService;
    }

    @GetMapping("/monoTest")
    public Mono<Object> monoTest() {
        return Mono.create(cityMonoSink -> {
            String data = demoService.getOneResult("monoTest()");
            cityMonoSink.success(data);
        });
    }


    @GetMapping("/fluxTest")
    public Flux<Object> fluxTest() {
        return Flux.fromIterable(demoService.getMultiResult("fluxTest()"));
    }
}
